<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="作品名称" prop="artName">
        <el-input
          v-model="queryParams.artName"
          placeholder="请输入作品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="分类">
        <el-select v-model="queryParams.cIds" multiple placeholder="请选择分类" >
          <el-option
            v-for="item in dict.type.p_category"
            :key="parseInt(item.value)"
            :label="item.label"
            :value="parseInt(item.value)"
            :disabled="item.raw.status == 1"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="摆放空间">
        <el-select v-model="queryParams.pIds" multiple placeholder="请选择摆放空间" >
          <el-option
            v-for="item in dict.type.p_placement"
            :key="parseInt(item.value)"
            :label="item.label"
            :value="parseInt(item.value)"
            :disabled="item.raw.status == 1"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="风格">
        <el-select v-model="queryParams.sIds" multiple placeholder="请选择风格" >
          <el-option
            v-for="item in dict.type.p_style"
            :key="parseInt(item.value)"
            :label="item.label"
            :value="parseInt(item.value)"
            :disabled="item.raw.status == 1"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="题材">
        <el-select v-model="queryParams.tIds" multiple placeholder="请选择题材" >
          <el-option
            v-for="item in dict.type.p_theme"
            :key="parseInt(item.value)"
            :label="item.label"
            :value="parseInt(item.value)"
            :disabled="item.raw.status == 1"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="专业推荐">
        <el-select v-model="queryParams.profRec" placeholder="请选择专业推荐" >
          <el-option
            :label="''"
            :value="null"
          ></el-option>
          <el-option
            v-for="dict in dict.type.p_profrec"
            :key="parseInt(dict.value)"
            :label="dict.label"
            :value="parseInt(dict.value)"
          ></el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="热门作品">
        <el-select v-model="queryParams.pop" placeholder="请选择热门作品" >
          <el-option
            :label="''"
            :value="null"
          ></el-option>
          <el-option
            v-for="dict in dict.type.p_pop"
            :key="parseInt(dict.value)"
            :label="dict.label"
            :value="parseInt(dict.value)"
          ></el-option>
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:rental:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="isUpdateDisabled"
          @click="handleUpdate"
          v-hasPermi="['system:rental:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:rental:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:rental:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="rentalList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" width="50" align="center" prop="id" />
      <el-table-column label="作品名称" align="center" prop="artName" />
      <el-table-column label="作品尺寸" align="center" prop="artSize" />
      <el-table-column label="类型" align="center" prop="artType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.art_type" :value="scope.row.artType"/>
        </template>
      </el-table-column>
      <el-table-column label="专业推荐" align="center" prop="profRec" width="100px">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.profRec"
            active-value="1"
            inactive-value="0"
            @change="profRecStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>

      <el-table-column label="热门作品" align="center" prop="pop" width="100px">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.pop"
            active-value="1"
            inactive-value="0"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>

      <el-table-column label="艺术家姓名" align="center" prop="artistName" width="100px" maxlength="10" minlength="2" />

      <el-table-column label="封面图片" align="center" prop="rentalImg" width="100px">
        <template slot-scope="scope" >
          <el-popover
            placement="right"
            width="400"
            trigger="click">
            <img  :src="scope.row.rentalImg" width="400px" height="400px" >
            <img  slot="reference" :src="scope.row.rentalImg" width="100px" height="100px" >
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="详情图片" align="center" prop="artImgUrl" width="400px">
        <template slot-scope="scope" >
          <span v-for="(item2,index2) in scope.row.artImgUrl" >
            <el-popover
              placement="right"
              width="400"
              trigger="click">
              <img  :src="item2" width="400px" height="400px" >
              <img  slot="reference" :src="item2" width="100px" height="100px" >
            </el-popover>
            <!--    这个是实现点击图片放大功能的代码-->
          </span>
        </template>
      </el-table-column>
      <el-table-column label="商品价格" align="center" prop="price" />
      <el-table-column label="活动价格" align="center" prop="discountPrice" />
      <el-table-column label="租金(元/天)" align="center" prop="rentalFee" />
<!--      <el-table-column label="起租(月)数" align="center" prop="rentalDays" />-->

<!--      <el-table-column label="状态" align="center" prop="rentalStatus" width="100px">-->
<!--        <template slot-scope="scope">-->
<!--          <el-switch-->
<!--            v-model="scope.row.rentalStatus"-->
<!--            active-value="1"-->
<!--            inactive-value="0"-->
<!--            @change="artStatusChange(scope.row)"-->
<!--          ></el-switch>-->
<!--        </template>-->
<!--      </el-table-column>-->

      <el-table-column prop="rentalStatus" label="状态" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.art_status" :value="scope.row.rentalStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="活动折扣" align="center" prop="artImgUrl" >
        <template slot-scope="scope" >
          <span v-if="scope.row.activityDiscountPrice!=0">{{ scope.row.activityDiscountPrice }}折</span>
        </template>
      </el-table-column>
      <el-table-column label="活动折扣开始时间" align="center" prop="discountStartDate" width="200px" />
      <el-table-column label="活动折扣结束时间" align="center" prop="discountEndDate"  width="200px" />
      <el-table-column label="活动特价价格" align="center" prop="artImgUrl">
        <template slot-scope="scope" >
          <span v-if="scope.row.activitySpecialPrice!=null">{{ scope.row.activitySpecialPrice }}元</span>
        </template>
      </el-table-column>
      <el-table-column label="活动特价开始时间" align="center" prop="specialStartDate" width="200px" />
      <el-table-column label="活动特价结束时间" align="center" prop="specialEndDate" width="200px" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  fixed="right" width="200">
        <template slot-scope="scope">
          <el-button v-if="scope.row.rentalStatus == '0'"size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:rental:edit']" >修改</el-button>
          <el-button v-if="scope.row.rentalStatus == '0'"size="mini" type="text" icon="el-icon-edit" @click="typeHandleUpdate(scope.row)" >设置折扣</el-button>
          <el-button v-if="scope.row.rentalStatus == '0'"size="mini" type="text" icon="el-icon-edit" @click="typeHandleUpdate(scope.row)" >设置</el-button>
          <el-button  size="mini" type="text" icon="el-icon-edit" @click="pShowFtn(scope.row)" >设置人数</el-button>
          <el-button v-if="scope.row.rentalStatus == '0'" size="mini" type="text" icon="el-icon-edit" @click="artStatusChange(scope.row)" >上架</el-button>
          <el-button v-if="scope.row.rentalStatus == '1'" size="mini" type="text" icon="el-icon-edit" @click="artStatusChange(scope.row)" >下架</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:rental:remove']" >删除</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="setActivityDiscount(scope.row)">设置活动折扣</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="setActivitySpecial(scope.row)">设置活动特价</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="作品名称" prop="artName">
              <el-input v-model="form.artName" placeholder="请输入作品名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="作品尺寸" prop="artSize">
              <el-input v-model="form.artSize" placeholder="请输入作品尺寸" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="艺术家姓名" prop="artistName">
              <el-input v-model="form.artistName" placeholder="请输入艺术家姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商品价格" prop="price">
              <el-input v-model="form.price" placeholder="请输入商品价格" >
                <template slot="append">￥</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="租赁单价(天)" prop="rentalFee">
              <el-input v-model="form.rentalFee" placeholder="请输入租赁单价" >
                <template slot="append">￥</template>
              </el-input>
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">
            <el-form-item label="起租(月)数" prop="rentalDays">
              <el-input v-model="form.rentalDays" placeholder="请输入起租月数" />
            </el-form-item>
          </el-col>-->
<!--          <el-col :span="12">
            <el-form-item label="出售价格" prop="saleFee">
              <el-input v-model="form.saleFee" placeholder="请输入出售价格" >
                <template slot="append">￥</template>
              </el-input>
            </el-form-item>
          </el-col>-->
        </el-row>





        <el-form-item label="封面图片" prop="imgUrl">
          <ImageUpload limit="1" v-model="form.rentalImg" ></ImageUpload>
        </el-form-item>

        <el-form-item label="详情图片" prop="imgUrl">
          <ImageUpload limit="3" v-model="form.artImgUrl" ></ImageUpload>
        </el-form-item>

        <el-row>
          <el-col :span="8">
            <el-form-item label="专业推荐">
              <el-radio-group v-model="form.profRec">
                <el-radio
                  v-for="dict in dict.type.p_profrec"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="热门作品">
              <el-radio-group v-model="form.pop">
                <el-radio
                  v-for="dict in dict.type.p_pop"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否装裱">
              <el-radio-group v-model="form.artFramed">
                <el-radio
                  v-for="dict in dict.type.p_framed"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="分类">
          <el-select v-model="form.cIds" multiple placeholder="请选择分类" style="width:500px">
            <el-option
              v-for="item in dict.type.p_category"
              :key="parseInt(item.value)"
              :label="item.label"
              :value="parseInt(item.value)"
              :disabled="item.raw.status == 1"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="摆放空间">
          <el-select v-model="form.pIds" multiple placeholder="请选择摆放空间" style="width:500px">
            <el-option
              v-for="item in dict.type.p_placement"
              :key="parseInt(item.value)"
              :label="item.label"
              :value="parseInt(item.value)"
              :disabled="item.raw.status == 1"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="风格">
          <el-select v-model="form.sIds" multiple placeholder="请选择风格" style="width:500px">
            <el-option
              v-for="item in dict.type.p_style"
              :key="parseInt(item.value)"
              :label="item.label"
              :value="parseInt(item.value)"
              :disabled="item.raw.status == 1"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="题材">
          <el-select v-model="form.tIds" multiple placeholder="请选择题材" style="width:500px">
            <el-option
              v-for="item in dict.type.p_theme"
              :key="parseInt(item.value)"
              :label="item.label"
              :value="parseInt(item.value)"
              :disabled="item.raw.status == 1"
            ></el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="作品图片路径" prop="artImgUrl">
          <el-input v-model="form.artImgUrl" placeholder="请输入作品图片路径" disabled/>
        </el-form-item>

        <el-form-item label="详情图片" prop="rentalImg">
          <el-input v-model="form.rentalImg" placeholder="请输入详情图片" disabled/>
        </el-form-item>

        <el-form-item label="作品描述" prop="artDescription">
          <editor v-model="form.artDescription" :min-height="192"/>
        </el-form-item>

        <el-form-item label="作者简介" prop="artAuthorDesc">
          <textarea v-model="form.artAuthorDesc" placeholder="请输入作者简介" style="width:100%;height:100px"></textarea>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="typetitle" :visible.sync="typeopen" width="800px" append-to-body>
          <el-form ref="typeform" :model="typeform" :rules="typerules" label-width="100px">
                    <el-form-item label="下拉选择" prop="artType">
                      <el-select v-model="typeform.artType" placeholder="请选择下拉选择">
                        <el-option v-for="item in dict.type.art_type"
                                   :key="item.key"
                                   :label="item.label"
                                   :value="item.value" >
                        </el-option>
                      </el-select>
                    </el-form-item>

            <el-form-item v-if="typeform.artType === '1'" label="折扣率" prop="discountRate">
              <el-input-number v-model="typeform.discountRate" :min="0" :max="99" :step="1"  style="width: 150px;margin-left: 10px" @change="changePrice" /> %
            </el-form-item>
            <el-form-item  label="商品原价：" prop="artDescription">
                <el-input v-model="typeform.price" style="width: 150px;margin-left: 12px" disabled>
                <template #suffix>
                  <span>¥</span>
                </template>
                </el-input>
              </el-form-item>
            <el-form-item v-if="typeform.artType === '1'" label="折扣价：" prop="artDescription">
              <el-input v-model="typeform.discountPrice" style="width: 150px;margin-left: 12px" disabled>
                <template #suffix>
                  <span>¥</span>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item v-if="typeform.artType === '2'" label="特惠价：" prop="artDescription">
              <el-input v-model="typeform.discountPrice" style="width: 150px;margin-left: 12px">
              <template #suffix>
                <span>¥</span>
              </template>
              </el-input>
            </el-form-item>
          </el-form>
      <div slot="footer">
        <el-button type="primary" @click="handleConfirm">确定</el-button>
      </div>
    </el-dialog>
    <!-- 设置活动折扣 -->
    <el-dialog title="设置活动折扣" :visible.sync="activitydiscount" width="600px" append-to-body>
          <el-form ref="activitydiscountform" :model="activitydiscountform" :rules="activitydiscountformrules" >
            <el-form-item  label="折扣" prop="activityDiscountPrice">
              <el-input-number v-model="activitydiscountform.activityDiscountPrice" :min="0" :max="99" :step="1"  @change="changePrice" />
            </el-form-item>
            <el-form-item  label="活动开始日期" prop="discountStartDate">
                <el-date-picker
              v-model="activitydiscountform.discountStartDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择折扣活动开始日期">
            </el-date-picker>
            </el-form-item>
            <el-form-item  label="活动结束日期" prop="discountEndDate">
                <el-date-picker
              v-model="activitydiscountform.discountEndDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择折扣活动结束日期">
            </el-date-picker>
            </el-form-item>
          </el-form>
      <div slot="footer">
        <el-button type="primary" @click="activitydiscountConfirm('activitydiscountform')">确定</el-button>
      </div>
    </el-dialog>
      <!-- 设置活动特价 -->
      <el-dialog title="设置活动折扣" :visible.sync="activityspecial" width="600px" append-to-body>
          <el-form ref="activityspecialform" :model="activityspecialform" :rules="activityspecialformrules" >
            <el-form-item  label="特价价格" prop="activitySpecialPrice">
              <el-input-number v-model="activityspecialform.activitySpecialPrice" :min="0" :max="99" :precision="2" :step="1"  />
            </el-form-item>
            <el-form-item  label="活动开始日期" prop="specialStartDate">
                <el-date-picker
              v-model="activityspecialform.specialStartDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择折扣活动开始日期">
            </el-date-picker>
            </el-form-item>
            <el-form-item  label="活动结束日期" prop="specialEndDate">
                <el-date-picker
              v-model="activityspecialform.specialEndDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="选择折扣活动结束日期">
            </el-date-picker>
            </el-form-item>
          </el-form>
      <div slot="footer">
        <el-button type="primary" @click="setActivitySpecialConfirm">确定</el-button>
      </div>
    </el-dialog>
    <!--人数设置-->
    <el-dialog title="人数设置" :visible.sync="pShow" width="800px" append-to-body>
      <el-form ref="pform" :model="pform"  label-width="100px">

        <el-form-item  label="浏览人数" prop="favorite">
          <el-input-number v-model="pform.favorite" :min="0"  :step="1"  style="width: 150px;margin-left: 10px"  />
        </el-form-item>
        <el-form-item  label="收藏人数" prop="viewHistory">
          <el-input-number v-model="pform.viewHistory" :min="0"  :step="1"  style="width: 150px;margin-left: 10px"  />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" @click="editPshow">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRental,
  getRental,
  delRental,
  addRental,
  updateRental,
  changePopStatus,
  changeProfRecStatus,
  setdiscount,
  setspecial
} from "@/api/system/rental";
import {changeUserStatus} from "@/api/system/user";
import dict from "@/utils/dict";

export default {
  name: "Rental",
  dicts: ['p_pop','p_profrec','p_framed','p_style','p_theme','p_placement','p_category','art_status','art_type'],
  data() {
    var validatePass = (rule, value, callback) => {
      console.log(rule,value);
      console.log(this.zerohourprice);
      console.log(this.zerohourprice<= value,"ddd");
      
      if (value === '') {
          callback(new Error('请输入活动特价价格'));
        } else if (this.zerohourprice<= value) {
          callback(new Error('特价价格不能大于或等于商品价格'));
        } else {
          callback();
        }
      };
    return {
 
      // 折扣
      activitydiscount:false,
      activitydiscountform:{
        id:"",
        activityDiscountPrice:"",
        discountStartDate:"",
        discountEndDate:"",
      },
      activitydiscountformrules:{
        activityDiscountPrice:[{ required: true, message: "请输入活动折扣", trigger: "blur"}],
        discountStartDate:[{ required: true, message: "请选择活动开始时间", trigger: "change"}],
        discountEndDate:[{ required: true, message: "请选择活动开始结束", trigger: "change"}],
      },
      // 特价
      activityspecial:false,
      activityspecialform:{
        id:"",
        activitySpecialPrice:"",
        specialStartDate:"",
        specialEndDate:"",
      },
      activityspecialformrules:{
        // activitySpecialPrice:[{ required: true, message: "请输入活动特价价格", trigger: "blur"}],
        activitySpecialPrice:[{validator: validatePass, trigger: 'blur'}],
        specialStartDate:[{ required: true, message: "请选择活动开始时间", trigger: "change"}],
        specialEndDate:[{ required: true, message: "请选择活动开始结束", trigger: "change"}],
      },
      
      zerohourprice:0,
      selItem:{},
      pform:{
        favorite:0,
        viewHistory:0,
      },
      pShow:false,
      checkedItems: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品表格数据
      rentalList: [],
      // 弹出层标题
      title: "",
      typetitle: "",
      // 是否显示弹出层
      open: false,
      typeopen: false,price:0,
      categoryList: [],placementList:[],styleList:[],themeList:[],isUpdateDisabled: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: "id",
        artName: null,
        artSize: null,
        artDescription: null,
        profRec: null,
        pop: null,
        artistName: null,
        carouselImg: null,
        artImgUrl: null,
        price: null,
        rentalDays: null,
        rentalStartDate: null,
        rentalEndDate: null,
        rentalFee: null,
        saleFee: null,
        tenantName: null,
        contactInformation: null,
        rentalStatus: null,
        saleDate: null,
        rentalRemarks: null,
        rentalImg: null,
        rentalOrderNo: null
      },
      // 表单参数
      form: {},
      typeform: {},
      // 表单校验
      rules: {
        artName:[{ required: true, message: "商品名称不能为空", trigger: "blur"}],
        artSize:[{ required: true, message: "商品尺寸不能为空", trigger: "blur"}],
        price:[{ required: true, message: "商品价格不能为空", trigger: "blur"}],
        rentalDays:[{ required: true, message: "商品租赁天数不能为空", trigger: "blur"}],
        artistName:[{ required: true, message: "艺术家名称不能为空", trigger: "blur"}],
        rentalFee:[{ required: true, message: "商品租赁费不能为空", trigger: "blur"}],
        saleFee:[{ required: true, message: "商品销售费不能为空", trigger: "blur"}],
        artDescription:[{ required: true, message: "商品描述不能为空", trigger: "blur"}],
      },
      typerules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    dict,
    pShowFtn(item){
      this.selItem = item
      this.pShow = true
      this.pform.favorite = this.selItem.favorite
      this.pform.viewHistory = this.selItem.viewHistory
    },
    editPshow(){
      this.pform.id = this.selItem.id

      if(!this.pform.favorite){
        this.pform.favorite = 0
      }
      if(!this.pform.viewHistory){
        this.pform.viewHistory = 0
      }
      updateRental(this.pform).then(res=>{
        this.$modal.msgSuccess("操作成功");
        this.selItem ={}
        this.pShow = false
        this.getList()
      })
    },
    /** 查询商品列表 */
    getList() {
      this.loading = true;
      listRental(this.queryParams).then(response => {
        for( let index in response.rows){
          response.rows[index].artImgUrl =  response.rows[index].artImgUrl.split(',');//后端返回的是以，分隔的字符串，将其转化成字符串数组。
        }
        this.rentalList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log("商品列表", this.rentalList)
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    handleStatusChange(row) {
      let text = row.pop === "1" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.artName + '"热门作品吗？').then(function() {
        return changePopStatus(row.id, row.pop);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.pop = row.pop === "0" ? "1" : "0";
      });
    },
    artStatusChange(row) {
      let text = row.rentalStatus === "0" ? "上架" : "下架";
      this.$modal.confirm('确认要"' + text + '""' + row.artName + '"吗？').then(function() {
        let id = row.id;
        let rentalStatus = row.rentalStatus === '0'?'1':'0';
        return updateRental({id, rentalStatus});
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
        this.getList();
      }).catch(function() {//取消操作
        //row.rentalStatus = row.rentalStatus === "0" ? "1" : "0";
      });
    },
    profRecStatusChange(row) {
      let text = row.profRec === "1" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.artName + '"专业推荐吗？').then(function() {
        return changeProfRecStatus(row.id, row.profRec);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.profRec = row.profRec === "0" ? "1" : "0";
      });
    },
    changePrice() {
      this.typeform.discountPrice = (this.typeform.price * (1 - (this.typeform.discountRate/100))).toFixed(2);
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        artName: null,
        artFramed: null,
        artSize: null,
        artDescription: null,
        profRec: null,
        pop: null,
        artistName: null,
        artAuthorDesc: null,
        carouselImg: null,
        artImgUrl: null,
        price: null,
        rentalDays: null,
        rentalStartDate: null,
        rentalEndDate: null,
        rentalFee: null,
        saleFee: null,
        tenantName: null,
        contactInformation: null,
        rentalStatus: null,
        saleDate: null,
        rentalRemarks: null,
        rentalImg: null,
        rentalOrderNo: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.isUpdateDisabled = selection.some(item => item.rentalStatus !== '0');
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      if (row.rentalStatus > 0) {
        this.$modal.msgError("非下架商品禁止修改");
        return;
      }
      this.reset();
      const id = row.id || this.ids
      getRental(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商品";
      });
    },
    typeHandleUpdate(row) {
      if (row.rentalStatus > 0) {
        this.$modal.msgError("非下架商品禁止修改");
        return;
      }
      //this.reset();
     // const id = row.id || this.ids
      this.typeform = row;
      //this.typeform.artType = row.artType;
      //this.typeform.price = row.price;
      this.typeopen = true;
      this.typetitle = "设置类型";
      this.price = row.price;
      // getRental(id).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改商品";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      /**
       * 拼接处ids的字符串来
       * */

      this.$refs["form"].validate(valid => {
        if (valid) {

          let strFormatCids = this.getFormatStr(this.form.cIds,this.dict.type.p_category)
          let strFormatPIds = this.getFormatStr(this.form.pIds ,this.dict.type.p_placement)
          let strFormatSIds = this.getFormatStr(this.form.sIds,this.dict.type.p_style)
          let strFormatTIds = this.getFormatStr(this.form.tIds,this.dict.type.p_theme)

          this.form.strFormatCids =strFormatCids
          this.form.strFormatPids =strFormatPIds
          this.form.strFormatTids =strFormatSIds
          this.form.strFormatSids =strFormatTIds

          if (this.form.id != null) {
            updateRental(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRental(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    getFormatStr(ids,list){
      if(!ids ){
        ids = []
      }
      let temp =[]
      list.forEach(item=>{
        console.log(item.value,ids,ids.includes(item.value))
        ids.forEach(i=>{
          if(i == item.value){
            temp.push(item.label)
          }
        })

      })
      return temp.join(',')
    },
    handleConfirm() {
      this.$refs["typeform"].validate(valid => {
        if (valid) {

          const data = {
            id: this.typeform.id,
            artType: this.typeform.artType,
            price: this.typeform.price,
            discountRate: this.typeform.discountRate,
            discountPrice: this.typeform.discountPrice,
          }
          if (data.id != null) {
            updateRental(data).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.$modal.msgError("数据错误！！！");
          }
        }
      });

    },


    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商品编号为"' + ids + '"的数据项？').then(function() {
        return delRental(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/rental/export', {
        ...this.queryParams
      }, `rental_${new Date().getTime()}.xlsx`)
    },
    // 设置活动折扣
    setActivityDiscount(row){
      console.log(row);
      this.activitydiscountform.id=row.id
      this.activitydiscount=true
      
    },
    // 提交设置活动折扣
    activitydiscountConfirm(formName){
      this.$refs["activitydiscountform"].validate(valid => {
        console.log(valid);
        console.log(this.activitydiscountform);
        if (valid) {
              setdiscount(this.activitydiscountform).then(res=>{
                  if(res.code==200){
                    this.$modal.msgSuccess("提交成功");
                    this.activitydiscountform.id="",
                    this.activitydiscount=false
                  }
              })
          } else {
            console.log('error submit!!');
            return false;
          }
      });
    },
    // 设置活动特价
    setActivitySpecial(row){
      this.activityspecialform.id=row.id
      this.zerohourprice=row.price
      this.activityspecial=true,
      console.log(row);
    },
    // validatePass(rule, value, callback){
    //   console.log(rule,value);
    //   console.log(this.zerohourprice);
      
    //   if (value === '') {
    //       callback(new Error('请输入活动特价价格'));
    //     } else if (this.zerohourprice< value) {
    //       callback(new Error('特价价格不能大于商品价格'));
    //     } else {
    //       callback();
    //     }
    // },
    setActivitySpecialConfirm(){

      this.$refs["activityspecialform"].validate(valid => {
        console.log(valid);
        console.log(this.activityspecialform);
        if (valid) {
          setspecial(this.activityspecialform).then(res=>{
                  if(res.code==200){
                    this.$modal.msgSuccess("提交成功");
                    this.activityspecialform.id="",
                    this.activityspecial=false
                  }
              })
          } else {
            console.log('error submit!!');
            return false;
          }
      });
    }
  }
};
</script>
